package top.tenebrous.yzl.chat.utils;

import java.security.SecureRandom;
import java.util.Random;

public class VcodeUtils {
  private static final String SYMBOLS1 = "0123456789";
  private static final String SYMBOLS2 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  private static final Random RANDOM = new SecureRandom();

  public VcodeUtils() {
  }

  public static void main(String[] args) {
    System.out.println(randomVcode());
  }

  public static String randomVcode() {
    return randomVcode(6);
  }

  public static String randomVcode(int length) {
    char[] nonceChars = new char[length];

    for(int index = 0; index < nonceChars.length; ++index) {
      nonceChars[index] = "0123456789".charAt(RANDOM.nextInt("0123456789".length()));
    }

    return new String(nonceChars);
  }

  public static String randomVgcode() {
    return randomVgcode(4);
  }

  public static String randomVgcode(int length) {
    char[] nonceChars = new char[length];

    for(int index = 0; index < nonceChars.length; ++index) {
      nonceChars[index] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(RANDOM.nextInt("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".length()));
    }

    return new String(nonceChars);
  }
}
